<?php

use app\assets\BackendAsset as Asset;
use \app\models\tableModel\AdminRoleModel;

/* @var $this yii\web\View */
/* @var $model app\models\tableModel\AdminUserModel */
/* @var $form yii\widgets\ActiveForm */

?>

<el-main class="content-wrapper no-pl no-pr no-border bg-gray">
    <el-form :model="form" :rules="formRules" ref="ruleForm" label-width="140px"
             class="form-600" :validate-on-rule-change="false">

        <el-card shadow="hover">
            <el-form-item label="账号" prop="user_name" class="form-item" :inline-message="true"
                          :error="customErrMsg.user_name" ref="formItem_user_name">

                <el-input v-model="form.user_name" size="small" class="form-element">
                </el-input>

            </el-form-item>

            <el-form-item label="昵称" prop="nick_name" class="form-item" :inline-message="true"
                :error="customErrMsg.nick_name" ref="formItem_nick_name">

                <el-input v-model="form.nick_name" size="small" class="form-element">
                </el-input>

            </el-form-item>

            <el-form-item label="密码" prop="password" class="form-item" :inline-message="true"
                          :error="customErrMsg.password" ref="formItem_password"
                          v-if="setting.isCreate">

                <el-input v-model="form.password" size="small" class="form-element">
                </el-input>

            </el-form-item>
        </el-card>

        <el-card shadow="hover">
            <el-form-item label="状态" prop="status" class="form-item"
                    :error="customErrMsg.status" ref="formItem_status">

                <el-radio-group v-model="form.status" size="mini">
                    <el-radio v-for="item in setting.status_list" :label="item.value">
                        {{item.text}}
                    </el-radio>
                </el-radio-group>

            </el-form-item>

            <el-form-item label="角色" prop="role_id" class="form-item"
                    :error="customErrMsg.role_id" ref="formItem_role_id">

                <el-select v-model="form.role_id" placeholder="请选择" size="small"
                           class="form-item">
                    <el-option v-for="item in roleList" :key="item.id" :label="item.name"
                            :value="item.id">
                    </el-option>
                </el-select>

            </el-form-item>
        </el-card>

        <div class="form-bottom-free"></div>
        <div class="form-bottom-free"></div>
    </el-form>
</el-main>

<el-footer class="bottom-button" :height="50">
    <el-button size="mini" type="danger" @click="cancel" v-show="pageDialog.isIframe">
        取消
    </el-button>
    <?php if (AdminRoleModel::checkAuth('create')) { ?>
    <el-button size="mini" type="success" @click="submit" v-if="setting.isCreate === true">
        创建
    </el-button>
    <?php } ?>
    <?php if (AdminRoleModel::checkAuth('update')) { ?>
    <el-button size="mini" type="primary" @click="submit" v-if="setting.isCreate === false">
        保存
    </el-button>
    <?php } ?>
</el-footer>

<?php
Asset::addCss($this, '/css/backend/admin-user-form.css');
Asset::addScript($this, '/js/backend/admin-user-form.js');

$isCreate = !isset($isCreate) || !$isCreate ? 'false' : 'true'; // 是否新建
$this->registerJs('instance = new app(' . $isCreate . ');');
?>
